package com.xuecheng.content.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * @author 勾新杰
 * @description: 令牌配置
 * @date 2023/1/11 16:04
 * @version 1.0
 **/
@Configuration
public class TokenConfig {

    /**
     * 令牌签名使用的密钥，公钥，可以用环境变量优化
     */
    private static final String SIGNING_KEY = System.getenv("JWT_SIGNING_KEY");

    /**
     * 配置令牌的存储
     * @return TokenStore
     */
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }

    /**
     * 配置对jwt令牌的支持
     * @return JwtAccessTokenConverter
     */
    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(SIGNING_KEY);
        return converter;
    }
}
